{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "healthy-replica",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/toeplitz-matrix\n",
    "\n",
    "\n",
    "Runtime: 12 ms, faster than 83.54% of C++ online submissions for Toeplitz Matrix.\n",
    "Memory Usage: 17.9 MB, less than 6.67% of C++ online submissions for Toeplitz Matrix.\n",
    "\n",
    "\n",
    "```c++\n",
    "#include <vector>\n",
    "#include <algorithm>\n",
    "#include <iostream>\n",
    "\n",
    "using namespace std;\n",
    "\n",
    "\n",
    "class Solution {\n",
    "public:\n",
    "    int height, width;\n",
    "    vector<vector<int>> matrix;\n",
    "    bool is_in_matrix(int x, int y) {\n",
    "        if ((x < width) && (y < height)) {\n",
    "            return true;\n",
    "        } else {\n",
    "            return false;\n",
    "        }\n",
    "    }\n",
    "    bool does_it_ok(int start_x, int start_y) {\n",
    "        if (!is_in_matrix(start_x, start_y)) {\n",
    "            return false;\n",
    "        } else {\n",
    "            int value = matrix[start_y][start_x];\n",
    "            while (is_in_matrix(start_x+1, start_y+1)) {\n",
    "                start_x += 1;\n",
    "                start_y += 1;\n",
    "                if (matrix[start_y][start_x] != value) {\n",
    "                    return false;\n",
    "                }\n",
    "            }\n",
    "            return true;\n",
    "        }\n",
    "    }\n",
    "\n",
    "    bool isToeplitzMatrix(vector<vector<int>>& matrix) {\n",
    "        //8:21\n",
    "        height = matrix.size();\n",
    "        width = matrix[0].size();\n",
    "        this->matrix = matrix;\n",
    "        for (int y=0; y<matrix.size(); y++) {\n",
    "            if (does_it_ok(0, y) == false) {\n",
    "                return false;\n",
    "            }\n",
    "        }\n",
    "        for (int x=0; x<matrix[0].size(); x++) {\n",
    "            if (does_it_ok(x, 0) == false) {\n",
    "                return false;\n",
    "            }\n",
    "        }\n",
    "        return true;\n",
    "        //8:29\n",
    "    }\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "wrong-oakland",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
